<?php

namespace App\Jobs;

use App\Store\Models\Wxapp\WxappCouponCodeList;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class CouponCodeRollback implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public $initdata;
    public function __construct($data)
    {
        //
        $this->initdata=$data;
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        //
        $coupon_code=isset($this->initdata['coupon_code'])?$this->initdata['coupon_code']:'';
        $mem_id=isset($this->initdata['mem_id'])?$this->initdata['mem_id']:0;

        if($coupon_code && $mem_id){
            $info=WxappCouponCodeList::where(['coupon_code'=>$coupon_code,'mem_id'=>$mem_id,'is_receive'=>1])->first();
            
            $info && WxappCouponCodeList::where(['coupon_code'=>$coupon_code,'mem_id'=>$mem_id,'is_receive'=>1])->update(['mem_id'=>0]);
        }
        Log::info($this->initdata);
        Log::info('已执行');
    }
}
